Skip to content

feat: add language and instructions support for mind maps#277

Open
voidborne-d wants to merge 1 commit intoteng-lin:mainfrom
voidborne-d:feat/mind-map-language-instructions-v2
Open

feat: add language and instructions support for mind maps#277
voidborne-d wants to merge 1 commit intoteng-lin:mainfrom
voidborne-d:feat/mind-map-language-instructions-v2

Conversation

@voidborne-d
Copy link
Copy Markdown
Contributor

@voidborne-d voidborne-d commented Apr 13, 2026

Summary

  • add language and instructions parameters to ArtifactsAPI.generate_mind_map()
  • wire generate mind-map CLI through --language plus optional freeform instructions
  • add regression tests for the RPC payload and CLI argument forwarding

Testing

  • PYTHONPATH=src python3 -m pytest tests/unit/test_source_selection.py tests/unit/cli/test_generate.py -q

Fixes #250

Summary by CodeRabbit

  • New Features
    • Mind map generation now supports custom language selection.
    • Users can provide optional instructions to guide mind map generation behavior.
    • CLI command accepts new --language option and optional description parameter for enhanced control over generated mind maps.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 13, 2026

📝 Walkthrough

Walkthrough

The changes extend mind map generation functionality with language and instructions parameters across the API and CLI layers, enabling customized generation with language selection and instruction injection into the RPC payload.

Changes

Cohort / File(s) Summary
API Layer
src/notebooklm/_artifacts.py
Added language: str = "en" and instructions: str | None = None parameters to generate_mind_map(). Updated RPC payload to inject instructions into [CONTEXT] field and pass language parameter, replacing previously hardcoded empty string and language value.
CLI Layer
src/notebooklm/cli/generate.py
Extended generate_mind_map command to accept positional description argument and --language option. Updated artifact generation call to forward language=resolve_language(language) and instructions=description or None in both JSON and console output paths.
Unit Tests
tests/unit/cli/test_generate.py
Added new test for generate mind-map CLI subcommand verifying --language ja and instruction string are properly forwarded to mocked client.artifacts.generate_mind_map() with correct kwargs.
Unit Tests
tests/unit/test_source_selection.py
Added new async test test_generate_mind_map_language_and_instructions for ArtifactsAPI.generate_mind_map asserting RPC payload contains language="zh-CN" and instruction text injected into [CONTEXT] field.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A mind map grows with words so bright,
Languages spoken left and right,
Instructions whispered in the fold,
Stories in a hundred tongues retold! 🗺️✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding language and instructions support for mind maps, which is the primary objective of this PR.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #250: adds language and instructions parameters to generate_mind_map(), updates RPC payload structure, and exposes CLI flags.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the issue requirements: API updates, CLI integration, and corresponding tests. No unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ability to specify a language and custom instructions when generating mind maps. The changes include updating the generate_mind_map method in the artifacts API to accept these new parameters, adding a description argument and --language option to the CLI, and including comprehensive unit tests for both the API and CLI layers. Feedback was provided to refactor the CLI logic to avoid redundant calls and improve code clarity by resolving parameters once before use.

Comment on lines 1021 to 1035
if json_output:
result = await client.artifacts.generate_mind_map(
nb_id_resolved, source_ids=sources
nb_id_resolved,
source_ids=sources,
language=resolve_language(language),
instructions=description or None,
)
else:
with console.status("Generating mind map..."):
result = await client.artifacts.generate_mind_map(
nb_id_resolved, source_ids=sources
nb_id_resolved,
source_ids=sources,
language=resolve_language(language),
instructions=description or None,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for resolving the language and instructions is duplicated across the if/else branches. Additionally, calling resolve_language multiple times within the same function can be inefficient if it involves file I/O. It's better to resolve these values once and reuse them to improve efficiency and clarity.

Suggested change
if json_output:
result = await client.artifacts.generate_mind_map(
nb_id_resolved, source_ids=sources
nb_id_resolved,
source_ids=sources,
language=resolve_language(language),
instructions=description or None,
)
else:
with console.status("Generating mind map..."):
result = await client.artifacts.generate_mind_map(
nb_id_resolved, source_ids=sources
nb_id_resolved,
source_ids=sources,
language=resolve_language(language),
instructions=description or None,
)
lang = resolve_language(language)
instr = description or None
if json_output:
result = await client.artifacts.generate_mind_map(
nb_id_resolved,
source_ids=sources,
language=lang,
instructions=instr,
)
else:
with console.status("Generating mind map..."):
result = await client.artifacts.generate_mind_map(
nb_id_resolved,
source_ids=sources,
language=lang,
instructions=instr,
)
References
  1. To improve efficiency and clarity, avoid reading the same file multiple times within a single function. Instead, read the file once, store its contents in a variable, and reuse the variable.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/notebooklm/cli/generate.py`:
- Around line 997-998: Add a new Click option --instructions (e.g.,
`@click.option`("--instructions", default=None, help="Mind-map instructions;
overrides positional description")) alongside the existing positional argument
"description" and "--language"; then update the command handler to prefer the
--instructions value when present and fall back to the positional description
for backward compatibility (replace usages that currently read the positional
"description" at the call sites referenced around lines 1002, 1023-1026, and
1031-1034 so they use instructions = instructions if instructions is not None
else description). Ensure the option help text clearly states it overrides the
positional description.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cfdc7b29-52c4-4a38-a582-35a4febf2af5

📥 Commits

Reviewing files that changed from the base of the PR and between a997718 and c88dd04.

📒 Files selected for processing (4)
  • src/notebooklm/_artifacts.py
  • src/notebooklm/cli/generate.py
  • tests/unit/cli/test_generate.py
  • tests/unit/test_source_selection.py

Comment on lines +997 to +998
@click.argument("description", default="", required=False)
@click.option("--language", default=None, help="Output language (default: from config or 'en')")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add an explicit --instructions option for mind-map generation.

The implementation currently supports instructions only via positional description, but the stated objective requires a dedicated --instructions flag.

Proposed fix (keep positional text for backward compatibility)
 `@generate.command`("mind-map")
 `@click.option`(
@@
 )
 `@click.argument`("description", default="", required=False)
+@click.option(
+    "--instructions",
+    default=None,
+    help="Custom instructions for mind map generation",
+)
 `@click.option`("--language", default=None, help="Output language (default: from config or 'en')")
 `@click.option`("--source", "-s", "source_ids", multiple=True, help="Limit to specific source IDs")
 `@json_option`
 `@with_client`
-def generate_mind_map(ctx, notebook_id, description, language, source_ids, json_output, client_auth):
+def generate_mind_map(
+    ctx, notebook_id, description, instructions, language, source_ids, json_output, client_auth
+):
@@
     async def _run():
         async with NotebookLMClient(client_auth) as client:
             nb_id_resolved = await resolve_notebook_id(client, nb_id)
             sources = await resolve_source_ids(client, nb_id_resolved, source_ids)
+            resolved_instructions = instructions if instructions is not None else (description or None)
@@
                 result = await client.artifacts.generate_mind_map(
                     nb_id_resolved,
                     source_ids=sources,
                     language=resolve_language(language),
-                    instructions=description or None,
+                    instructions=resolved_instructions,
                 )
             else:
                 with console.status("Generating mind map..."):
                     result = await client.artifacts.generate_mind_map(
                         nb_id_resolved,
                         source_ids=sources,
                         language=resolve_language(language),
-                        instructions=description or None,
+                        instructions=resolved_instructions,
                     )

Also applies to: 1002-1002, 1023-1026, 1031-1034

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/notebooklm/cli/generate.py` around lines 997 - 998, Add a new Click
option --instructions (e.g., `@click.option`("--instructions", default=None,
help="Mind-map instructions; overrides positional description")) alongside the
existing positional argument "description" and "--language"; then update the
command handler to prefer the --instructions value when present and fall back to
the positional description for backward compatibility (replace usages that
currently read the positional "description" at the call sites referenced around
lines 1002, 1023-1026, and 1031-1034 so they use instructions = instructions if
instructions is not None else description). Ensure the option help text clearly
states it overrides the positional description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mind map generation ignores language and instructions parameters

1 participant